<?

//Initiate Authenticate
SecurityRedirect ();

//initiate Vars
define("PRIMARY_KEY","act_nr_id");
$KEY[]         = array("PRIMARY_KEY"=>PRIMARY_KEY);
$FileName      = "ais_transaction_bslist.php";
$FileTemplate  = "ais_transaction_bslist_list.html";

$PageSize      = 10 ;
$TableName     = "ais_advance";
$HTMLGridList  = "ActivityNRGrid";

//************ FORM ACTION **************
    if (GetParam("Action","")=="Delete") {
        DeleteRecord ("txtCheck",$PageSize);
    }

$PreserveGet = GetQueryString("All", array("PageNum"));
//Initiate Database Table For Search;
$FNama = GetParam("nameSearch","");
$FCode = GetParam("codeSearch","");

$temp_no_urut = GetParam("no_urut","");
$service_id = GetParam("service_id","");
$jo_id = GetParam("jo_id","");

if(!empty($temp_no_urut))
{
  $no_urut = GetParam("no_urut","");

}
else
{
   $no_urut = "";
}

$FormName = GetParam("FormName","");

//******* DATABASE FORM QUERY ***********

$SQL = "SELECT *, a.nobkt as nobs FROM $TableName a 
		JOIN tbljoborder b ON a.jo_id = b.jo_id 
		JOIN ais_memorial c ON a.nobkt = c.noref";

				
if ($FNama)
    if (strlen($WHERE)) $WHERE .= " AND "." actname like '%".$FNama."%'";
    else $WHERE .= " actname like '%".$FNama."%'";
if ($FCode)
    if (strlen($WHERE)) $WHERE .= " AND "." actcode like '%".$FCode."%'";
    else $WHERE .= " actcode like '%".$FCode."%'";

    if (strlen($WHERE)) $WHERE = " WHERE a.services_id = '".$service_id."' AND ".$WHERE;
    else $WHERE = " WHERE a.jo_id=".$jo_id." AND c.urut=999 AND a.bs_progress <> 'closed'";
    //else $WHERE = " WHERE a.services_id = '".$service_id."' ";


$SQL = $SQL.$WHERE;




//COUNT

$WHERE = "";

$SQLCount = "SELECT count(*) FROM $TableName a 
			 JOIN tbljoborder b ON a.jo_id = b.jo_id 
			 JOIN ais_memorial c ON a.nobkt = c.noref";

if ($FNama)
    if (strlen($WHERE)) $WHERE .= " AND "." actname like '%".$FNama."%'";
    else $WHERE .= " actname like '%".$FNama."%'";
if ($FCode)
    if (strlen($WHERE)) $WHERE .= " AND "." actcode like '%".$FCode."%'";
    else $WHERE .= " actcode like '%".$FCode."%'";

    if (strlen($WHERE)) $WHERE = " WHERE a.services_id = '".$service_id."' AND ".$WHERE;
    else $WHERE = " WHERE a.jo_id=".$jo_id." AND c.urut=999 AND a.bs_progress <> 'closed'";
    //else $WHERE = " WHERE a.services_id = '".$service_id."' ";


$SQLCount = $SQLCount.$WHERE;




//echo "$SQL";

//******* SHOW FORM CONTENT *********

//$PageNum = 1;
//$RecCnt = $DBConnection->dbc->get_var($SQLCount) ;
//if (GetParam("PageNum","")) $PageNum  = GetParam("PageNum","");

if (GetParam("PageNum","")) $PageNum  = GetParam("PageNum","");
//Default value
if (!isset($_GET)) $_GET=&$HTTP_GET_VARS ;
if (isset($_GET['PageNum'])) {
  $PageNum = $_GET['PageNum'] ;
} else {
    $PageNum = 1 ;
}

//Default value
if (isset($_GET['RecCnt'])) {
  $RecCnt = intval($_GET['RecCnt']) ;
} else {
    $RecCnt = -1 ;
}


$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate($MOD_TEMPLATE_DIR."/".$FileTemplate);
$TBS->MergeBlock("bln",$KEY);
$RecCnt = $TBS->MergeBlock("blg",$DBMysql,$SQL,$PageSize,$PageNum,$RecCnt);
$TBS->MergeNavigationBar('nv',array('size'=>10,'pos'=>'centred'),$PageNum,$RecCnt,$PageSize) ;
$TBS->Show();



?>
